/****************************************************************
*****************************************************************/

#ifndef __JZM_X264_T20_ENC_H__
#define __JZM_X264_T20_ENC_H__
#include <stdint.h>

#include "jzm_vpu.h"

#define SCH_FIFO_DEPTH  (16)

/************************************************************
 CHN Space Allocation
 ************************************************************/
#define VRAM_DUMMY          (VPU_BASE | 0xFFFFC)

#define VRAM_MAU_RESA       (VPU_BASE | 0xC0000)  //residual address
#define VRAM_MAU_RES_SIZE   (SCH_FIFO_DEPTH*256*4)

#define VRAM_RAWY_BA        (VPU_BASE | 0xF0000)
#define VRAM_RAWC_BA        (VRAM_RAWY_BA + 256)
#define VRAM_RAW_SIZE       (SCH_FIFO_DEPTH*128*4)

#define VRAM_TOPPA_BA       (VRAM_MAU_RESA+VRAM_MAU_RES_SIZE)  //recover address
#define VRAM_TOPMV_BA       (VRAM_TOPPA_BA+VPU_MAX_MB_WIDTH*8)

#define VRAM_MAU_CHN_BASE   (VRAM_TOPMV_BA+VPU_MAX_MB_WIDTH*4)
#define VRAM_MAU_CHN_SIZE   (SCH_FIFO_DEPTH*16*4)
#define VRAM_DBLK_CHN_BASE  (VRAM_MAU_CHN_BASE + VRAM_MAU_CHN_SIZE)
#define VRAM_DBLK_CHN_SIZE  (SCH_FIFO_DEPTH*16*4)
#define VRAM_ME_CHN_BASE    (VRAM_DBLK_CHN_BASE + VRAM_DBLK_CHN_SIZE)
#define VRAM_ME_CHN_SIZE    (SCH_FIFO_DEPTH*8*4)
#define VRAM_SDE_CHN_BASE   (VRAM_ME_CHN_BASE + VRAM_ME_CHN_SIZE)
#define VRAM_SDE_CHN_SIZE   (SCH_FIFO_DEPTH*8*4)
#define VRAM_QP_TAB_BA      (VRAM_SDE_CHN_BASE + VRAM_SDE_CHN_SIZE)

#define VRAM_ME_DSA         DSA_SCH_CH1
#define VRAM_MAU_DEC_SYNA   DSA_SCH_CH2
#define VRAM_DBLK_CHN_SYNA  DSA_SCH_CH3
#define VRAM_SDE_SYNA       DSA_SCH_CH4

#define VRAM_MAU_ENC_SYNA   VRAM_DUMMY
#define VRAM_DBLK_DOUT_SYNA VRAM_DUMMY

#define VRAM_ME_MVPA        (VPU_BASE | REG_EFE_MVRP)

typedef unsigned int paddr_t;

#define __ALN32__ __attribute__ ((aligned(4)))

typedef struct{
  uint8_t roi_en;
  uint8_t roi_md;
  int8_t  roi_qp;
  uint8_t roi_lmbx;
  uint8_t roi_rmbx;
  uint8_t roi_umby;
  uint8_t roi_bmby;
}ROI_info;
/*
  _H264E_SliceInfo:
  H264 Encoder Slice Level Information
 */
typedef struct _H264E_SliceInfo {
  /*basic*/
  uint8_t frame_type;
  uint8_t mb_width;
  uint8_t mb_height;
  uint8_t first_mby;
  uint8_t last_mby;  //for multi-slice

  /* motion */
  int frame_width;
  int frame_height;
  uint8_t frm_re[4];
  uint8_t scl;
  uint8_t hpel_en;
  uint8_t qpel_en;
  uint8_t ref_mode;
  uint32_t max_sech_step_i;
  uint32_t max_mvrx_i;
  uint32_t max_mvry_i;
  uint8_t lambda_scale_parameter;
  uint8_t fs_en; //fs function enable
  uint8_t fs_px; //fs period x
  uint8_t fs_py; //fs period y
  uint8_t fs_rx; //fs range x, must be multiples of 3
  uint8_t fs_ry; //fs range y, must be multiples of 3
  /*vmau scaling list*/
  uint8_t __ALN32__ scaling_list[4][16];
  int deadzone[4];

  uint32_t intra_mode_msk;

  uint8_t i_4x4_dis;
  uint8_t i_16x16_dis;
  uint8_t p_l0_dis;
  uint8_t p_skip_dis;

  uint8_t cost_bias_en;
  uint8_t cost_bias_i_4x4;
  uint8_t cost_bias_i_16x16;
  uint8_t cost_bias_p_l0;
  uint8_t cost_bias_p_skip;

  uint8_t intra_lambda_y_bias_en;
  uint8_t intra_lambda_c_bias_en;
  uint8_t intra_lambda_bias_qp0;
  uint8_t intra_lambda_bias_qp1;
  uint8_t intra_lambda_bias_0;
  uint8_t intra_lambda_bias_1;
  uint8_t intra_lambda_bias_2;

  uint8_t chroma_sse_bias_en;
  uint8_t chroma_sse_bias_qp0;
  uint8_t chroma_sse_bias_qp1;
  uint8_t chroma_sse_bias_0;
  uint8_t chroma_sse_bias_1;
  uint8_t chroma_sse_bias_2;

  uint8_t sse_lambda_bias_en;
  uint8_t sse_lambda_bias;

  uint8_t fbc_ep;
  uint8_t jm_lambda2_en;
  uint8_t inter_nei_en;
  uint8_t skip_bias_en;

  uint8_t info_en;
  uint8_t mvd_sum_all;
  uint8_t mvd_sum_abs;
  uint8_t mv_sum_all;
  uint8_t mv_sum_abs;

  uint32_t ysse_thr;
  uint32_t csse_thr;

  /*loop filter*/
  uint8_t deblock;
  uint8_t rotate;
  int8_t alpha_c0_offset;
  int8_t beta_offset;

  /*cabac*/
  uint8_t *state;
  paddr_t bs;             /*BS output address*/
  uint8_t qp;
  uint8_t skip_en;
  int8_t cqp_offset;
  /*mode decision*/
  uint8_t use_intra_in_pframe;
  uint8_t use_fast_mvp;

  /*frame buffer address: all of the buffers should be 256byte aligned!*/
  paddr_t fb[2][2];       /*{curr, ref}{tile_y, tile_c}*/
  paddr_t raw[3];         /*{rawy, rawu, rawv} or {rawy, rawc, N/C}*/
  int stride[2];          /*{stride_y, stride_c}, only used in raster raw*/

  /* RAW plane format */
  uint8_t raw_format;

  /*descriptor address*/
  paddr_t *des_va, *des_pa;

  /*TLB address*/
  paddr_t tlba;

  /* ROI info */
  ROI_info roi_info[8];
  uint8_t max_qp;
  uint32_t *qp_tab;
  uint8_t qpg_en;
  uint32_t qp_tab_len;

  /* VPU Daisy Chain setting */
  uint8_t daisy_chain_en;
  uint8_t curr_thread_id;

}_H264E_SliceInfo;

__place_k0_data__
//extern uint32_t lps_range[64];

/*
  H264E_T20_SliceInit(_H264E_SliceInfo *s)
  @param s: slice information structure
 */
void H264E_T20_SliceInit(_H264E_SliceInfo *s);

#endif /*__JZM_H264E_H__*/
